<?php

/**
 * This is the model class for table "{{pickdata}}".
 *
 * The followings are the available columns in table '{{pickdata}}':
 * @property integer $RECORD_ID
 * @property integer $USER_ID
 * @property string $BTKEY_V
 * @property string $BASENAME_V
 * @property string $SENSORNAME_V
 * @property string $SENSOR_SETUP_NAME_V
 * @property integer $SENSOR_N
 * @property integer $BATTERY_N
 * @property string $VOL_N
 * @property string $ELEC_N
 * @property string $INTER_N
 * @property string $HINTER_N
 * @property string $TEMPER_N
 * @property string $REMARK_V
 */
class Pickdata extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Pickdata the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{pickdata}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('USER_ID, SENSOR_N, BATTERY_N', 'numerical', 'integerOnly'=>true),
			array('BTKEY_V, BASENAME_V, SENSORNAME_V, SENSOR_SETUP_NAME_V, REMARK_V', 'length', 'max'=>255),
			array('VOL_N, ELEC_N, INTER_N, HINTER_N, TEMPER_N', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('RECORD_ID, USER_ID, BTKEY_V, BASENAME_V, SENSORNAME_V, SENSOR_SETUP_NAME_V, SENSOR_N, BATTERY_N, PICKEDTIME_D, VOL_N, ELEC_N, INTER_N, HINTER_N, TEMPER_N, STATUS_V, REMARK_V', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'RECORD_ID' => '流水',
			'USER_ID' => '用户',
			'BTKEY_V' => '电池组名称',
			'BASENAME_V' => '站点名称',
			'SENSORNAME_V' => '传感器名称',
			'SENSOR_SETUP_NAME_V' => '传感器建立时间',
			'SENSOR_N' => '传感器编号',
			'BATTERY_N' => '电池编号',
			'PICKEDTIME_D' => '采集时间',
			'VOL_N' => '电压',
			'ELEC_N' => '电流',
			'INTER_N' => '电阻',
			'HINTER_N' => '混流排电阻',
			'TEMPER_N' => '温度',
			'STATUS_V' => '采集状态',
			'REMARK_V' => '备注',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		
		//filter the user data
		$uid = Yii::app()->user->id;
		
		$criteria->compare('RECORD_ID',$this->RECORD_ID);
//		$criteria->compare('USER_ID',$this->USER_ID);
		$criteria->compare('USER_ID',$uid);
		$criteria->compare('BTKEY_V',$this->BTKEY_V,true);
		$criteria->compare('BASENAME_V',$this->BASENAME_V,true);
		$criteria->compare('SENSORNAME_V',$this->SENSORNAME_V,true);
		$criteria->compare('SENSOR_SETUP_NAME_V',$this->SENSOR_SETUP_NAME_V,true);
		$criteria->compare('SENSOR_N',$this->SENSOR_N);
		$criteria->compare('BATTERY_N',$this->BATTERY_N);
		$criteria->compare('PICKEDTIME_D',$this->PICKEDTIME_D);
		$criteria->compare('VOL_N',$this->VOL_N,true);
		$criteria->compare('ELEC_N',$this->ELEC_N,true);
		$criteria->compare('INTER_N',$this->INTER_N,true);
		$criteria->compare('HINTER_N',$this->HINTER_N,true);
		$criteria->compare('TEMPER_N',$this->TEMPER_N,true);
		$criteria->compare('STATUS_V',$this->STATUS_V,true);
		$criteria->compare('REMARK_V',$this->REMARK_V,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}